package easy;

public class Solution_387 {

    public static int firstUniqChar(String s) {
        int[] arr = new int[26];
        Integer[] indexes = new Integer[26];
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            int index = chars[i] - 97;
            arr[index]++;
            if (indexes[index]==null) {
                indexes[index] = i;
            }
        }
        int index = chars.length;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==1) {
                index = Math.min(index, indexes[i]);
            }
        }
        return index==chars.length?-1:index;
    }

    public static void main(String[] args) {
        System.out.println(firstUniqChar("leetcode"));
        System.out.println(firstUniqChar("loveleetcode"));
    }
}
